package cn.aresoft.framework.exception;

import java.sql.SQLException;

public class ActionException extends BaseException {
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -6895485541372880462L;

	//store the message content from other system
	private String[] messageArray;
	private String causeMessage;

	public ActionException(){
		super("ERR_AS_UNKNOWN");
	}
	
	public ActionException(String errorCode) {
		super(errorCode);
	}
	
	public ActionException(String errorCode,String[] msg) {
		super(errorCode);
		this.messageArray = msg;
	}
	
	public ActionException(String errorCode, Throwable e) {
		super(errorCode, e);
		if(e instanceof ActionException){
			ActionException ae = (ActionException)e;
			this.setErrorCode(ae.getErrorCode());
			this.causeMessage = ae.getCauseMessage();
		}else{
			this.causeMessage = getCauseMessage(e);
		}
		
	}
	
	public ActionException(String errorCode,String[] msg, Throwable e) {
		super(errorCode, e);
		this.messageArray = msg;
		this.causeMessage = getCauseMessage(e);
	}
	
	
	private static String getCauseMessage(Throwable e ){
		if(e==null){
			return null;
		}else{
			return e.getMessage();
		}
	}
	
	public String[] getMessageArray() {
		return messageArray;
	}

	public String getCauseMessage() {
		return causeMessage;
	}
	
	public void setCauseMessage(String causeMessage) {
		this.causeMessage = causeMessage;
	}
	
	public void setMessageArray(String[] messageArray) {
		this.messageArray = messageArray;
	}
	
	public static void main(String[] args){
		SQLException e = new SQLException("SQLException");
		ActionException ee = new ActionException("ER-001",e);
		System.out.println(ee.getErrorCode());
		System.out.println(ee.getMessage());
		System.out.println(ee.getCause().getMessage());
	}
}
